package org.ithasu.tools.bugOne;

import org.ithasu.tools.Console;
import org.ithasu.tools.IOTools;
import org.ithasu.tools.bugOne.SerialSniffer.MessageListener;

public class SerialTester {

	public static void main(String[] args) {
		Console.DEBUG = true;

		SerialSniffer s = new SerialSniffer();
		if (!s.connect("/dev/ttyUSB0", 19200)) {
			Console.error("Failed to connect");
		} else {
			Console.message("Connected at " + s.getSerialPort().getBaudRate());
		}
		s.addMessageListener(new MessageListener() {
			@Override
			public void onMessageReceived(SerialSniffer sniffer, byte[] message) {
				Console.message("-- Message received --");
				System.out.println("Size: " + message.length);
				for (int i = 0; i < message.length; i++) {
					System.out.print(IOTools.toHexByte(message[i]));
					System.out.print(", ");
				}
				System.out.println();
			}
		});
	}

}
